home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 140_01.zip / WCT2.C < prev    next >
Text File  |  1993-06-26  |  3KB  |  134 lines

  1. /* 
  2.  
  3. word count program which also calculates column centimetres 
  4. oµ magazinσ (o≥ newspaper⌐ cop∙ fo≥ would-bσ contributors« 
  5. Se⌠ u≡ fo≥ Helveticß Medium phototype which is the body copy 
  6. used in Your Computer magazine, but can be easily changed 
  7. for others. Original structure taken from `The C Programming 
  8. Language', via BDSC users group (wc.c) and modified since 
  9. then by YC staff....
  10.  
  11. Version YC.01, 4/6/82
  12. */
  13.  
  14.  
  15. #include    <bdscio.h>
  16.  
  17. #define    YES    1
  18. #define    NO    0
  19. #define    EOF    0x1a
  20. #define ERROR    -1
  21. #define MASK    0x7f
  22.  
  23. char toupper();        
  24.  
  25. main(argc,argv)    /* count lines, words, chars in input file */
  26. char    **argv;
  27. {
  28.     int c, nl, nw, nc, inword, fd, m;
  29.     char    buf[BUFSIZ];
  30.  
  31.     if(argc != 2) {
  32.         printf("Usage: wc filename\n");
  33.         exit();
  34.     }
  35.  
  36.     if((fd = fopen(argv[1],buf)) == ERROR) {
  37.         printf("cannot open: %s\n",argv[1]);
  38.         exit();
  39.     }
  40.     inword = NO;
  41.     nl = nw = nc = 0;
  42.     while ((c = (getc(buf) & MASK)) != EOF)
  43.     {
  44.         ++nc;
  45.         if (c == '\n')
  46.             ++nl;
  47.         if (c == ' ' || c == '\n' || c == '\t' || c == 0x0d)
  48.             inword = NO;
  49.         else if (inword == NO) {
  50.             inword = YES;
  51.             ++nw;
  52.         }
  53.     }
  54.     menu();
  55.     while (m != "5") {                 /* the m!=5 is irrelevant, but at
  56.                           least sets up the loop */
  57.     printf("\nWhich would you like? ");
  58.     m = getchar();
  59.         switch (toupper(m)) {
  60.  
  61.         case '1':
  62.             printf("\n\n\n");
  63.             printf("number of chars    = %d\n",nc);
  64.             printf("number of lines    = %d\n",nl);
  65.             printf("number of words    = %d\n",nw);
  66.             printf("column centimetres = %d\n",nw/20);
  67.             break;
  68.         case '2':
  69.             printf("\n\n\n");
  70.             printf("number of chars    = %d\n",nc);
  71.             printf("number of lines    = %d\n",nl);
  72.             printf("number of words    = %d\n",nw);
  73.             printf("column centimetres = %d\n",nw/24);
  74.             break;
  75.         case '3':
  76.             printf("\n\n\n");
  77.             printf("number of chars    = %d\n",nc);
  78.             printf("number of lines    = %d\n",nl);
  79.             printf("number of words    = %d\n",nw);
  80.             printf("column centimetres = %d\n",nw/12);
  81.             break;
  82.         case '4':
  83.             printf("\n\n\n");
  84.             printf("number of chars = %d\n",nc);
  85.             printf("number of lines = %d\n",nl);
  86.             printf("number of words = %d\n",nw);
  87.             printf("haven't worked it out yet!\n");
  88.             break;
  89.         case 'X':
  90.             printf("\n\n\n");
  91.             printf("number of chars = %d\n",nc);
  92.             printf("number of lines = %d\n",nl);
  93.             printf("number of words = %d\n",nw);
  94.             printf("bibi\n");
  95.             exit();
  96.         case 'M':
  97.             menu();
  98.             break;
  99.         default:
  100.             putch(7);
  101.             printf("\nEnter 1-4 for measure, M for menu");
  102.             break;
  103.             }
  104.         }
  105. }
  106.  
  107. menu()
  108. {
  109.     printf(CLEARS);        /* Hope you have screen-clear defined
  110.                    in bdscio.h                */ 
  111.  
  112.     printf("SELECT:\n");
  113.  
  114.     printf("<1> ---> 9/10 x 13 1/2 ems\n");   /*9point type, 1point
  115.                             leading - the standard 
  116.                             3-column type used in the
  117.                             magazine                */
  118.  
  119.     printf("<2> --->  8/9 x 13 1/2 ems\n");   /*slightly smaller type over 
  120.                             same column with - used for
  121.                             copy with "pocket programs"*/
  122.  
  123.     printf("<3> ---> 9/10 x  9 1/2 ems\n");   /*normal type size, narrow
  124.                             column width for news and
  125.                             "clinic" pages */
  126.  
  127.     printf("<4> ---> 9/10 x 20 1/2 ems\n");   /* 2-column (1/2-page) width*/
  128.  
  129.     printf("<X> ---> ++ eXit ++\n");
  130.  
  131. }
  132.  
  133.  
  134.